package com.oo.array_$.case_2;

import java.util.Arrays;
import java.util.Scanner;

/**
 * StudentDemo--编写JAVA程序，实现学生JAVA成绩统计。
 * 接收用户输入的学员人数，依次录入学员的JAVA考试成绩，输出前三名学员考试成绩
 要求：
 1、验证学员人数必须为正整数，如果不是，提示“人数无效”，并结束程序
 2、验证JAVA成绩的有效性（1—100），如果无效，提示“成绩无效”，并结束程序
 3、使用Arrays.sort()方法实现数组排序
 *
 * @author: Jovi
 * @createTime: 2017-05-11 15:46
 **/
public class StudentDemo {
    public static void main(String[] args) {
        System.out.println("Please enter the number of the students：");
        Scanner sc = new Scanner(System.in);
        int count = sc.nextInt();
        if (count < 3) {
            System.out.println("the number of the students is invalid");
            return;
        }
        int[] scores = new int[count];

        /* Circulation receives input Java performance */
        for (int i = 0; i < scores.length; i++) {
            System.out.println("Please enter the " + (i + 1) + "student performance");
            scores[i] = sc.nextInt();
            if (scores[i] > 100 || scores[i] < 0) {
                System.out.println("The performance is invalid");
                return;
            }
        }
        System.out.println("====================");
        Arrays.sort(scores);
        /* The top three grades of students */
        for (int i = scores.length - 1; i > scores.length - 4; i--) {
            System.out.println(scores[i]+"\t");
        }
    }
}
